<?php
namespace App\Services;
use Exception;
use Illuminate\Support\Facades\Cache;
use EasyWeChat\Factory;
use GuzzleHttp\Client;
use Yansongda\Pay\Pay;
use Log;

class PayService
{
    public static function getPayParams($type,$type_detial,$title,$out_trade_no,$price,$openid,$appid,$status)
    {
        if ($type == "alipay") {
            $config = config("pay.alipay");
            if ($type_detial == "app") {
                return Pay::alipay($config)->app([
                    'out_trade_no' => $out_trade_no,
                    'total_amount' => $price,
                    'subject' => $title,
                    'passback_params'=>$status,
                ])->getContent();
            }
        } elseif ($type == "wechat") {
            $config = config("pay.wechat");
            $config["miniapp_id"] = $appid;
            if ($type_detial == "mini") {
                $order = [
                    'out_trade_no' => $out_trade_no,
                    'total_fee' => round($price*100,0),
                    'body' => $title,
                    'attach' => $status,
                    'openid' => $openid,
                ];
                return Pay::wechat($config)->miniapp($order);
            } elseif ($type_detial == "app") {
                $order = [
                    'out_trade_no' => $out_trade_no,
                    'description' => $title,
                    'amount' => [
                        'total' => $price*1000,
                    ],
                ];
                return Pay::wechat($config)->app($order);
            }
        }
    }
}
